package com.ikunikun.mapper;

import com.github.pagehelper.Page;
import com.ikunikun.annotation.AutoFill;
import com.ikunikun.dto.DishPageQueryDTO;
import com.ikunikun.entity.Dish;
import com.ikunikun.enumeration.OperationType;
import com.ikunikun.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from sky_take_out.dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 添加菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据主键查询菜品
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.dish where id = #{id}")
    Dish getById(Long id);

    @Delete("delete from sky_take_out.dish where id = #{id}")
    void deleteById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @Select("select * from sky_take_out.dish where category_id = #{categoryId}")
    List<DishVO> getByCategoryId(Long categoryId);

    @Select("select d.* from sky_take_out.setmeal_dish s join sky_take_out.dish d on s.dish_id = d.id where s.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    @Select("select * from sky_take_out.dish where category_id = #{categoryId} and status = #{status}")
    List<Dish> listWithCategoryId(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
